import http from '@/utils/request.ts'
import type { DocumentItem, DocumentItemRequest } from '@/modules/doc/types/doc.ts'

export const documentItemApi = {
  // 根据文档ID获取所有子项
  getByDocumentId: async (documentId: string): Promise<DocumentItem[]> => {
    const response = await http.get<DocumentItem[]>(`/document-item/document/${documentId}`)
    return response.data || []
  },

  // 根据ID获取子项详情
  getById: async (id: string): Promise<DocumentItem> => {
    const response = await http.get<DocumentItem>(`/document-item/${id}`)
    return response.data
  },

  // 创建文档子项
  create: async (request: DocumentItemRequest): Promise<DocumentItem> => {
    const response = await http.post<DocumentItem>('/document-item', request)
    return response.data
  },

  // 更新文档子项
  update: async (id: string, request: DocumentItemRequest): Promise<DocumentItem> => {
    const response = await http.put<DocumentItem>(`/document-item/${id}`, request)
    return response.data
  },

  // 切换文档子项完成状态
  toggleComplete: async (id: string): Promise<DocumentItem> => {
    const response = await http.put<DocumentItem>(`/document-item/${id}/toggle-complete`)
    return response.data
  },

  // 删除文档子项
  delete: async (id: string): Promise<boolean> => {
    const response = await http.delete<boolean>(`/document-item/${id}`)
    return response.data
  }
}